<?php
namespace  Admin\Controller;
use Utuo\BackgroundController;
class RoleController extends BackgroundController
{   private  $status=array(
			'1'=>'开启',
			'0'=>'关闭'	
		);
	public  function _initialize(){
		$this->setControllerTitle('角色管理');
		$this->setActionTitle(array(
				'index' => '角色列表',
				'add' => '添加角色',
				'modify' => '修改角色',
				'recycle' => '回收站',
				
		));
		$this->setActionNav(array(
				'index',
				'add',
				'recycle'
		));
	}   
	public function getLists($is_deleted)
	{   $condation=array(
		'is_deleted'=>$is_deleted	
	    );
		$role=M('Role')->where($condation)->select();
		
		$this->assign("role",$role);
		$this->display();
	}
	public function addAction(){
	$role['radio']=\Utuo\Form::getRadio("status", $this->status,1);
	$this->assign('role',$role);
	$this->display('save');
	}
	public function modifyAction($id)
	{
		$role=M('role')->getById($id);
		$role['radio']=\Utuo\Form::getRadio("status", $this->status,$role['status']);
		$this->assign('role',$role);
		$this->display('save');
	}
	public function accessAction($rid){
		$nodeIds=M('access')->where('role_id='.$rid)->getField('node_id',true);
		$nodeIds=implode($nodeIds,',');
	    $nodes=M('node')->where('status=1 and is_deleted=0')->select();
	    $nodes=makeListLevel($nodes,0,'pid');
        $this->assign("rid",$rid);
        $this->assign("nodeIds",$nodeIds);
		$this->assign('nodes',$nodes);
		$this->display();
	}
	public function setAccessAction(){
		$role_id=I('role_id');
		M('access')->where('role_id='.$role_id)->delete();
		$array=I('access');
		foreach ($array as $v)
		{
			$temp=explode('-', $v);
			M('access')->add(array(
				'role_id'=>$role_id,
				'node_id'=>$temp[0],
				'level'=>$temp[1]
			));
		}
		
		$this->success("修改成功",U('Role/index'));
	}
}